package cn.yzfy.orm.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;

/**
 * @author 一朝风月
 * @date 2025/9/10 22:46
 * @Code 面向注解面向卿，终无解释再无你
 * @description omr-mybatis-plus 配置类
 */

@Configuration
@EnableTransactionManagement
@NoArgsConstructor
@Slf4j
public class MPConfig {
    // mybatis plus 拦截器对象
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        interceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());
        log.info("MPConfig.mybatisPlusInterceptor()--------loading");
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
        log.info("MPConfig.mybatisPlusInterceptor()--------loading");
        return interceptor;
    }
}
